package com.su.middle.db.connection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionHelper {
	
	private static boolean isInit = false;
	
	public static Connection getConnection() {
		Connection conn = null;

		try {
			if (!isInit) {
				Class.forName("com.mysql.jdbc.Driver").newInstance();
				isInit = true;
			}

		    conn =
		       DriverManager.getConnection("jdbc:mysql://localhost/middle?" +
		                                   "user=middledb&password=middledb");

		} catch (SQLException ex) {
		    System.out.println("SQLException: " + ex.getMessage());
		    System.out.println("SQLState: " + ex.getSQLState());
		    System.out.println("VendorError: " + ex.getErrorCode());
		} catch (Exception iae) {
			iae.printStackTrace();
		}
		
		return conn;
	}
	
	public static void main(String[] a) {
		try {
			Connection conn = getConnection();
			conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
